package com.example.mymatch.controller;

import com.example.mymatch.service.IEmpService;
import com.example.mymatch.model.Emp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "员工")
@RestController
public class EmpController {
    @Autowired
    private IEmpService empService;//对某个业务服务的内容进行定义规范  编写者：谢楷诗
    @ApiOperation(value = "查询所有员工信息",notes = "获取员工信息返回json字符串")
    @RequestMapping("/getStr21")
    public String getEmp(){return "My emp";}
    @CrossOrigin
    @ApiOperation(value = "对员工信息的添加方法")
    @GetMapping("/addEmp")
    public int addEmp(Emp emp){
        System.out.println("进入添加员工信息接口");
        return empService.insertEmp(emp);
    }

    @GetMapping("getAll21")
    @ApiOperation(value = "对员工信息查询方法")
    public List<Emp> getAllEmp(Emp emp){
        System.out.println("进入查询方法");
        List<Emp> listEmp=empService.getAllEmp(emp);
        return listEmp;
    }
    @PutMapping("/editEmp")
    @ApiOperation(value = "对员工信息的修改方法")
    public int EditEmp(@RequestBody Emp emp){
        System.out.println("进入员工修改方法");
        return empService.updateEmp(emp);
    }
    @GetMapping("/delEmp")
    @ApiOperation(value = "对员工信息的删除方法")
    public int Delete(int id){
        System.out.println("进入员工删除方法");
        int returnValue=0;
        if (id!=0){
            Emp emp=new Emp();
            emp.setId(id);
            returnValue= empService.deleteEmp(emp);
        }
        return returnValue;
    }
    @GetMapping("/getOne21")
    @ApiOperation(value = "对单条员工信息的查询方法")
    public Emp getEmp(int id){
        Emp emp=new Emp();
        System.out.println("进入单条查询方法");
        if (id!=0){
            Emp emp1=new Emp();
            emp1.setId(id);
            emp=empService.getEmp(emp1);
            System.out.println("返回的数据集合为："+emp.getEmpName());
        }
        return emp;
    }
}
